package other.acm;

import java.util.Scanner;

public class poj1551 {
	/**
	 * 1551.   Digital Roots
	 * 
	 * */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String num ="" ;
		Integer sum =0;
		while(scan.hasNext()){
			
			num = scan.next();
			if (num.equals("0") ){
				break;
			}else{				
				sum = sumnum(num);
				while(sum>9){
					sum = sumnum(sum.toString());
				}
				System.out.println(sum);
			}			
		}
	}
	
	private static Integer sumnum(String newnum) {
		Integer subSum =0;
		
		for ( int  index=0 ; index< newnum.length() ;index++){
			Character s = newnum.charAt(index);
			//System.out.println("char:"+s);
			subSum = subSum+Integer.parseInt( s.toString());									
		}
		return subSum;
	}

}
